package org.example.elm_springboot.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.example.elm_springboot.po.DeliveryAddress;
import org.example.elm_springboot.service.DeliveryAddressService;

@RestController
@RequestMapping("/deliveryAddress")
public class DeliveryAddressController {
    
    @Autowired
    private DeliveryAddressService deliveryAddressService;
    
    @RequestMapping("/listDeliveryAddressByUserId")
    public List<DeliveryAddress> listDeliveryAddressByUserId(String userId) {
        return deliveryAddressService.listDeliveryAddressByUserId(userId);
    }
    
    @RequestMapping("/getDeliveryAddressById")
    public DeliveryAddress getDeliveryAddressById(Integer daId) {
        return deliveryAddressService.getDeliveryAddressById(daId);
    }
    
    @RequestMapping("/saveDeliveryAddress")
    public int saveDeliveryAddress(String contactName, Integer contactSex, String contactTel, String address, String userId) {
        DeliveryAddress deliveryAddress = new DeliveryAddress();
        deliveryAddress.setContactName(contactName);
        deliveryAddress.setContactSex(contactSex);
        deliveryAddress.setContactTel(contactTel);
        deliveryAddress.setAddress(address);
        deliveryAddress.setUserId(userId);
        return deliveryAddressService.saveDeliveryAddress(deliveryAddress);
    }
    
    @RequestMapping("/updateDeliveryAddress")
    public int updateDeliveryAddress(Integer daId, String contactName, Integer contactSex, String contactTel, String address) {
        DeliveryAddress deliveryAddress = new DeliveryAddress();
        deliveryAddress.setDaId(daId);
        deliveryAddress.setContactName(contactName);
        deliveryAddress.setContactSex(contactSex);
        deliveryAddress.setContactTel(contactTel);
        deliveryAddress.setAddress(address);
        return deliveryAddressService.updateDeliveryAddress(deliveryAddress);
    }
    
    @RequestMapping("/removeDeliveryAddress")
    public int removeDeliveryAddress(Integer daId) {
        return deliveryAddressService.removeDeliveryAddress(daId);
    }
} 